package com.yuluke.ylsaudiorecorder.record;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

public class RecordConfig {

    private RecordConfig() {

    }

    private static RecordConfig mInstance;

    public static RecordConfig getInstance() {
        if (mInstance == null) {
            synchronized (RecordConfig.class) {
                if (mInstance == null) mInstance = new RecordConfig();
            }
        }
        return mInstance;
    }

    public void setUp() {

    }

    public abstract class BaseConfig {
        public abstract int getSampleRate();
        public abstract int getBufferSize();
        public abstract int getSource();
        public abstract int getChannel();
        public abstract int getFormat();
    }

    class SimpleConfig extends BaseConfig {

        @Override
        public int getSampleRate() {
            return SAMPLE_RATE_441;
        }

        @Override
        public int getBufferSize() {
            return AudioRecord.getMinBufferSize(getSampleRate(), getChannel(), getFormat());
        }

        @Override
        public int getSource() {
            return MediaRecorder.AudioSource.MIC;
        }

        @Override
        public int getChannel() {
            return AudioFormat.CHANNEL_IN_MONO;
        }

        @Override
        public int getFormat() {
            return AudioFormat.ENCODING_PCM_16BIT;
        }
    }

    public BaseConfig getSimpleConfig() {
        return new SimpleConfig();
    }

    public static int SAMPLE_RATE_441 = 44100;
}
